using MediatR;
using Microsoft.AspNetCore.Mvc;
using WebMediaTRApi.Commands;
using WebMediaTRApi.Notifications;
using WebMediaTRApi.Services;
using WebMediaTRApi.WeatherForcasts;
using WebMediaTRApi.WeatherForcasts.Querys;

namespace WebMediaTRApi.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {

        private readonly IMediator _mediator;

        public WeatherForecastController(IMediator mediator)
        {
            _mediator = mediator;
        }

        [HttpGet( "GetWeatherForecast")]
    
        public async Task<IEnumerable<WeatherForecast>> Get()
        {
            var response = await _mediator.Send(new Weather_ForecastQuery());

            return response;
        }

        [HttpGet("GetTodayWeather")]
    
        public async Task<WeatherForecast> GetTodayWeather()
        {
            var response = await _mediator.Send(new Weather_TodayQuery());

            return response;
        }

        [HttpPost("CreateWeather")]
     
        public async Task<WeatherForecast> CreateWeather([FromBody] CreateWeatherCommand command)
        {
            WeatherForecast? response = await _mediator.Send(command);

            return response;
        }


        [HttpPost("CreateUser")]

        public async Task<bool> CreateUser([FromBody] NewUser command)
        {
           await _mediator.Publish(command);

            return true;
        }


        [HttpGet("GetPing")]
        //[Route("GetTodayWeather")]
        public async Task<string> GetPing()
        {
             await _mediator.Publish(new Ping());

            return "ok";
        }

        [HttpPost("CreateProduct")]
        //[Route("GetTodayWeather")]
        public async Task<string> CreateProduct([FromBody]CreateProductCommand createProductCommands)
        {
            await _mediator.Send(createProductCommands);

            return "ok";
        }

    }
}